#!/bin/bash

mpd_running=$(ps ax | grep "mpd" | grep -v "mpdrunning" | grep -v "grep")
count=$(mpc | wc -l)

if [ -n "$mpd_running" ]; then
	mpd_playing=$(mpc | head -n 1)
	mpd_playtrunc=$(echo ${mpd_playing})
	
	if [ `echo ${mpd_playtrunc} | wc -m` -ge 40 ]; then
		mpd_omg=$(echo ${mpd_playing:0:37} | sed -e "s/'. $'//" -e "s/\\.$//")
		mpd_play="${mpd_omg}..."
	else
		mpd_play="${mpd_playtrunc}"
	fi

	if [ $count -lt 3 ]; then
		echo "Now Playing: Nothing"
	else
		echo "Now Playing: ${mpd_play}"
	fi
else
        echo "MPD not running"
fi
